package com.cloudptt.wp.ui.address.workspace;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cloudptt.api.product.func.crsc.FuncNumOb;
import com.cloudptt.api.product.log.Log;
import com.cloudptt.wp.R;

import java.util.List;

class FuncAdapter extends BaseAdapter {
//        public static int[] item_icon_group = {
//            R.drawable.icon_main_func_add
//            ,R.drawable.icon_main_func_query
//            ,R.drawable.icon_main_func_query
//            ,R.drawable.icon_main_func_query
//            ,R.drawable.icon_main_func_logout_c
//			,R.drawable.icon_main_func_query
//            ,R.drawable.settings_about_us_icon
//    };
//
//    public static int[] item_title_group = {
//            R.string.func_login
//            ,R.string.func_query
//            ,R.string.func_addressing
//            ,R.string.func_local
//            ,R.string.func_msg
//			,R.string.func_compulsory
//            ,R.string.func_query_self
//    };
    private Context ctx = null;
    private List<FuncItemOb> funcNumObList = null;
    public FuncAdapter(Context ctx, List<FuncItemOb> funcNumObList)
    {
        this.ctx = ctx;
        this.funcNumObList = funcNumObList;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return funcNumObList.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return funcNumObList.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

        ViewHolder viewHolder = new ViewHolder();
        if(ctx != null) {
            if (convertView == null) {
                LayoutInflater inflater = LayoutInflater.from(ctx);
                if (inflater != null) {
                    convertView = inflater.inflate(R.layout.func_num_item_layout, parent, false);
                    viewHolder.icon = (ImageView)convertView.findViewById(R.id.settings_item_icon);
                    viewHolder.title = (TextView) convertView.findViewById(R.id.titleTv);
                    viewHolder.desc = (TextView) convertView.findViewById(R.id.despTv);
                    convertView.setTag(viewHolder);
                }
            } else {
                viewHolder = (ViewHolder) convertView.getTag();
            }
            FuncItemOb ob = funcNumObList.get(position);
            Log.debug(this.getClass(), "getView position = " + position + " ob = " + ob);

            viewHolder.icon.setImageResource(ob.getIcon());
            viewHolder.title.setText(ob.getName());
            viewHolder.desc.setText(ob.getDesc());
        }
        return convertView;
    }

}

final class ViewHolder{
    public ImageView icon;
    public TextView title;
    public TextView desc;

}
